package com.lion.appletrip;

import com.lion.appletrip.utils.AccessTokenKeeper;
import com.lion.appletrip.utils.PreferenceUtils;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;

public class SettingActivity extends Activity
{

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_setting);
		findViewById(R.id.btn_clearcache_setting).setOnClickListener(
		        new OnClickListener()
		        {

			        @Override
			        public void onClick(View v)
			        {
				        Toast.makeText(SettingActivity.this, "清除缓存成功",
				                Toast.LENGTH_SHORT).show();
			        }
		        });
		findViewById(R.id.btn_back_setting).setOnClickListener(
		        new OnClickListener()
		        {

			        @Override
			        public void onClick(View v)
			        {
						finish();
			        }
		        });
		findViewById(R.id.btn_exit_setting).setOnClickListener(
		        new OnClickListener()
		        {

			        @Override
			        public void onClick(View v)
			        {
				        AlertDialog.Builder builder = new AlertDialog.Builder(
				                SettingActivity.this);
				        builder.setTitle("提示");
				        builder.setMessage("确定要退出当前账号吗？");
				        builder.setPositiveButton(
				                "确认",
				                new android.content.DialogInterface.OnClickListener()
				                {

					                @Override
					                public void onClick(DialogInterface dialog,
					                        int which)
					                {
						                PreferenceUtils.setLogin(
						                        SettingActivity.this, false);
						                PreferenceUtils.setBomb(
						                		SettingActivity.this, false);
						                AccessTokenKeeper
						                        .clear(SettingActivity.this);
						                Intent intent = new Intent();
						                intent.setClass(SettingActivity.this,
						                        MainActivity.class);
						                intent.putExtra("Login", 0);
						                startActivity(intent);
						                finish();
					                }

				                }).setNegativeButton("取消", null).show();
			        }
		        });
	}

}
